package com.clps.digital.controller;

import cn.hutool.core.util.ObjectUtil;
import com.clps.digital.common.BaseResponse;
import com.clps.digital.common.ErrorCode;
import com.clps.digital.common.ResultUtils;
import com.clps.digital.model.entity.Slideshow;
import com.clps.digital.service.SlideshowService;

import java.util.List;

/**
 * @author: Chase
 * @date: 2024/9/3 10:43
 * @Version: 1.0
 * @description:
 */

public class SlideshowController {

    private SlideshowService slideshowService;

    /**
     * 获取轮播图数据
     * @return
     */
    public BaseResponse<List<Slideshow>> getSlideshowList() {
        List<Slideshow> slideshowList = slideshowService.getSlideshowList();
        if (ObjectUtil.isEmpty(slideshowList)) {
            return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR, "请求轮播图数据不存在");
        }
        return ResultUtils.success(slideshowList);
    }

    /**
     * 根据id获取轮播图数据
     * @return
     */
    public BaseResponse<Slideshow> getSlideshowById(Long id) {
        Slideshow slideshow = slideshowService.getSlideshowById(id);
        if (ObjectUtil.isEmpty(slideshow)) {
            return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR, "请求轮播图数据不存在");
        }
        return ResultUtils.success(slideshow);
    }
}
